//
//  BMHCashOutAuthorizeWebViewController.m
//  BMHVideoMain
//
//  Created by 陈宪栋 on 2017/7/13.
//  Copyright © 2017年 BAOMIHUA.COM. All rights reserved.
//

#import "BMHCashOutAuthorizeWebViewController.h"
#import "XLAnchorWorkVC.h"
#import "BMHCashOutViewController.h"
@interface BMHCashOutAuthorizeWebViewController ()<WKScriptMessageHandler>

@end

@implementation BMHCashOutAuthorizeWebViewController

- (BOOL)shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self customBackButton];
    self.webView.backgroundColor = [UIColor clearColor];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"111"];
}

- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
    NSLog(@"%@", message);
}
#pragma mark 拦截返回
- (void)customBackButton{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:[UIImage imageNamed:@"common_nav_btn_back_n"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    backBtn.frame = CGRectMake(0, 0, 40, 44);
    [backBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = item;
}
// 返回按钮按下
- (void)backBtnClicked:(UIButton *)sender{
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[BMHCashOutViewController class]]) {
            BMHCashOutViewController *A =(BMHCashOutViewController *)controller;
            [self.navigationController popToViewController:A animated:YES];
        }else{
            XLAnchorWorkVC *A =(XLAnchorWorkVC *)controller;
            [self.navigationController popToViewController:A animated:YES];
        }
    }
}
@end
